// stdx/iterx.rs
// CRITICAL: Iterator trait 与常见适配器示例（map, filter, fold, enumerate）。
// AUTO_COMMENT: 展示组合使用，保持无副作用。

#[allow(dead_code)]
pub fn stdx_examples_iterx() {
    let nums = 0..10;
    let sum: i32 = nums.filter(|n| n % 2 == 0).map(|n| n * 2).sum();

    let arr = [1, 2, 3];
    let enumerated: Vec<_> = arr.iter().enumerate().collect();

    let _ = (sum, enumerated);

    // CRITICAL: 迭代器的创建
    let vec_iter = vec![1, 2, 3].into_iter();
    let slice_iter = [1, 2, 3].iter();
    let range_iter = (0..5).into_iter();

    // CRITICAL: 常用适配器
    let doubled: Vec<i32> = (1..6).map(|x| x * 2).collect();
    let evens: Vec<i32> = (0..10).filter(|x| x % 2 == 0).collect();
    let first_even = (0..10).find(|x| x % 2 == 0);

    // CRITICAL: 消费器
    let count = (0..10).count();
    let sum_fold = (0..10).fold(0, |acc, x| acc + x);
    let max_val = (1..11).max();
    let min_val = (1..11).min();

    // CRITICAL: 高级适配器
    let zipped: Vec<(i32, i32)> = (1..4).zip(4..7).collect();
    let chained: Vec<i32> = (1..4).chain(4..7).collect();
    let flat_mapped: Vec<i32> = vec![vec![1, 2], vec![3, 4]].into_iter().flatten().collect();

    // CRITICAL: 短路操作
    let any_even = (1..10).any(|x| x % 2 == 0);
    let all_even = (2..10).step_by(2).all(|x| x % 2 == 0);

    let _ = (
        vec_iter,
        slice_iter,
        range_iter,
        doubled,
        evens,
        first_even,
        count,
        sum_fold,
        max_val,
        min_val,
        zipped,
        chained,
        flat_mapped,
        any_even,
        all_even,
    );
}
